﻿using PaytonByrd.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Text;
using System.Text.RegularExpressions;

namespace PaytonByrd.Extensions.UnitTests
{
    
    
    /// <summary>
    ///This is a test class for StringManipulationExtensionsTest and is intended
    ///to contain all StringManipulationExtensionsTest Unit Tests
    ///</summary>
    [TestClass()]
    public class StringManipulationExtensionsTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for ToDebug
        ///</summary>
        [TestMethod()]
        public void ToDebugTest1()
        {
            StringBuilder sb = new StringBuilder();
            System.IO.TextWriter writer = new System.IO.StringWriter(sb);
            System.Diagnostics.TraceListener listener =
                new System.Diagnostics.TextWriterTraceListener(writer);
            System.Diagnostics.Debug.Listeners.Add(listener);

            string source = "Test {0}"; // TODO: Initialize to an appropriate value
            object[] data = new string[] { "Data" }; // TODO: Initialize to an appropriate value
            string expected = "Test Data"; // TODO: Initialize to an appropriate value
            string actual;
            actual = source.ToDebug(data);
            listener.Flush();
            actual = sb.ToString().Trim();
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for ToDebug
        ///</summary>
        [TestMethod()]
        public void ToDebugTest()
        {
            StringBuilder sb = new StringBuilder();
            System.IO.TextWriter writer = new System.IO.StringWriter(sb);
            System.Diagnostics.TraceListener listener =
                new System.Diagnostics.TextWriterTraceListener(writer);
            System.Diagnostics.Debug.Listeners.Add(listener);

            string source = "Test Data"; // TODO: Initialize to an appropriate value
            string expected = "Test Data"; // TODO: Initialize to an appropriate value
            string actual;
            source.ToDebug(source);
            listener.Flush();
            actual = sb.ToString().Trim();
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for ToConsole
        ///</summary>
        [TestMethod()]
        public void ToConsoleTest1()
        {
            StringBuilder sb = new StringBuilder();
            System.Console.SetOut(new System.IO.StringWriter(sb));

            string source = "Test {0}"; // TODO: Initialize to an appropriate value
            object[] data = new string[] { "Data" }; // TODO: Initialize to an appropriate value
            string expected = "Test Data"; // TODO: Initialize to an appropriate value
            string actual;
            source.ToConsole(data);
            System.Console.Out.Flush();
            actual = sb.ToString().Trim();
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for ToConsole
        ///</summary>
        [TestMethod()]
        public void ToConsoleTest()
        {
            StringBuilder sb = new StringBuilder();
            System.Console.SetOut(new System.IO.StringWriter(sb));

            string source = "Test Data"; // TODO: Initialize to an appropriate value
            string expected = "Test Data"; // TODO: Initialize to an appropriate value
            string actual;
            source.ToConsole();
            System.Console.Out.Flush();
            actual = sb.ToString().Trim();
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for ToByteArray
        ///</summary>
        [TestMethod()]
        public void ToByteArrayTest()
        {
            string source = "ABC"; // TODO: Initialize to an appropriate value
            byte[] expected = new byte[] { 65, 66, 67 }; // TODO: Initialize to an appropriate value
            byte[] actual;
            actual = source.ToByteArray();
            Assert.AreEqual(expected[0], actual[0],"Index 0 does not match.");
            Assert.AreEqual(expected[1], actual[1], "Index 0 does not match.");
            Assert.AreEqual(expected[2], actual[2], "Index 0 does not match.");
        }

        /// <summary>
        ///A test for Matches
        ///</summary>
        [TestMethod()]
        public void MatchesTest()
        {
            string source = "Test Data"; // TODO: Initialize to an appropriate value
            string pattern = @"Test"; // TODO: Initialize to an appropriate value
            MatchCollection results = null; // TODO: Initialize to an appropriate value
            string expected = "Test";
            string actual = null;
            results = source.Matches(pattern);
            Assert.IsNotNull(results);
            Assert.IsFalse(results.Count == 0);
            actual = results[0].Value;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Match
        ///</summary>
        [TestMethod()]
        public void MatchTest()
        {
            string source = "Test Data"; // TODO: Initialize to an appropriate value
            string pattern = @"Test"; // TODO: Initialize to an appropriate value
            Match results = null; // TODO: Initialize to an appropriate value
            string expected = "Test";
            string actual = null;
            results = source.Match(pattern);
            Assert.IsNotNull(results);
            actual = results.Value;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for IsIn
        ///</summary>
        [TestMethod()]
        public void IsInTest()
        {
            string source = "def"; // TODO: Initialize to an appropriate value
            string[] strings = new string[] { "abc", "def", "ghi" }; // TODO: Initialize to an appropriate value
            bool expected = true; // TODO: Initialize to an appropriate value
            bool actual;
            actual = source.IsIn(strings);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Format
        ///</summary>
        [TestMethod()]
        public void FormatTest()
        {
            string source = "Test {0}"; // TODO: Initialize to an appropriate value
            object[] data = new string[] { "Data" }; // TODO: Initialize to an appropriate value
            string expected = "Test Data"; // TODO: Initialize to an appropriate value
            string actual;
            actual = source.Format(data);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for AsStringBuilder
        ///</summary>
        [TestMethod()]
        public void AsStringBuilderTest()
        {
            string source = "Test Data"; // TODO: Initialize to an appropriate value
            StringBuilder result = null; // TODO: Initialize to an appropriate value
            string expected = source;
            string actual = null;
            result = source.AsStringBuilder();
            Assert.IsNotNull(result);
            actual = result.ToString();
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for AppendFormat
        ///</summary>
        [TestMethod()]
        public void AppendFormatTest()
        {
            string source = "Test"; // TODO: Initialize to an appropriate value
            string format = " {0}"; // TODO: Initialize to an appropriate value
            object[] data = new string[] { "Data" }; // TODO: Initialize to an appropriate value
            string expected = "Test Data"; // TODO: Initialize to an appropriate value
            string actual;
            actual = source.AppendFormat(format, data);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for ToByteArray
        ///</summary>
        public void ToByteArrayTest1Helper<E>()
            where E : Encoding, new()
        {
            string source = "ABC"; // TODO: Initialize to an appropriate value
            byte[] expected = new byte[] { 65, 66, 67 }; // TODO: Initialize to an appropriate value
            byte[] actual;
            actual = source.ToByteArray<E>();
            Assert.AreEqual(expected[0], actual[0], "Index 0 does not match.");
            Assert.AreEqual(expected[1], actual[1], "Index 0 does not match.");
            Assert.AreEqual(expected[2], actual[2], "Index 0 does not match.");
        }

        [TestMethod()]
        public void ToByteArrayTest1()
        {
            ToByteArrayTest1Helper<System.Text.ASCIIEncoding>();
        }
    }
}
